﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Services;
using System.Web.Script.Serialization;

public partial class adm_vlg_gigRequest : System.Web.UI.Page
{
    CommonPage _cm = new CommonPage();
    VLGDataContext _db = new VLGDataContext();
    //string cateId = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack) return;

        fillDulieuLenGrid();

    }
    void fillDulieuLenGrid()
    {
        var gig = from gg2 in _db.GigRequests
                  orderby gg2.TimeInput descending
                  select gg2;

        GridView1.DataSource = gig;
        GridView1.DataBind();
    }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
    {
        fillDulieuLenGrid();
        GridView1.PageIndex = e.NewPageIndex;
        GridView1.DataBind();
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="idAcc"></param>
    /// <returns>
    /// 0 : có lỗi
    /// 1 : xóa thành công
    /// </returns>
    /// Van chua kiem tra admin moi duoc thao tac
    [WebMethod]
    public static int AdminActiveGigRequest(string idGigRequest, bool isActive)
    {

        if (!string.IsNullOrEmpty(idGigRequest))
        {
            try
            {

                VLGDataContext _dataContext = new VLGDataContext();
                CommonPage _comment = new CommonPage();
                var idGigInt = Convert.ToInt32(idGigRequest);
                var gigRequest = _dataContext.GigRequests.Select(p => p).Where(p => p.id == idGigInt).FirstOrDefault();
                if (isActive)
                    gigRequest.IsActive = true;
                else gigRequest.IsActive = false;
                _dataContext.SubmitChanges();
                return 1;
            }
            catch
            {

                return 0;
            }

        }
        else return 0;
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="idAcc"></param>
    /// <returns>
    /// 0 : có lỗi
    /// 1 : xóa thành công
    /// </returns>
    /// Van chua kiem tra admin moi duoc thao tac
    [WebMethod]
    public static int AdminDeleteGigRequest(string idGigRequest)
    {

        if (!string.IsNullOrEmpty(idGigRequest))
        {
            try
            {
                VLGDataContext _dataContext = new VLGDataContext();
                CommonPage _comment = new CommonPage();
                var idGigInt = Convert.ToInt32(idGigRequest);
                var gigRequest = _dataContext.GigRequests.Select(p => p).Where(p => p.id == idGigInt).FirstOrDefault();   
                _dataContext.GigRequests.DeleteOnSubmit(gigRequest);
                _dataContext.SubmitChanges();
                return 1;

            }
            catch
            {

                return 0;
            }

        }
        else return 0;
    }
}
